package com.situ.mall.config;


import com.situ.mall.converter.String2DateConverter;
import com.situ.mall.interceptor.LoginInterceptor;
import com.situ.mall.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private IUserService userService;
    /* <bean name="student" class="com.situ.springboot.entity.Student"/>*/
//    @Bean
//    public Student createStudent() {
//        Student student = new Student();
//        return student;
//    }

    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverter(new String2DateConverter());
    }

    //配置虚拟路径
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/pic/**")
                .addResourceLocations("file:/F:/Javasitu/mypic/");
        WebMvcConfigurer.super.addResourceHandlers(registry);
    }


    //这个方法用来配置拦截器，我们写的拦截器只有配置了才起作用
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor(userService))
                .addPathPatterns("/page/turntable", "/page/cart", "/cart/**", "/page/place/order", "/place/order/**", "/page/order/**", "/order/**", "/page/user/", "/page/user/**");
    }
}




